<template>
  <div>
    <Header></Header>
    <section>
      <Routers></Routers>
      <div id="section" class="main">
        <div class="common_header">
          <span class="common_header_tip">选择研发活动</span>
          <!--<div>-->
          <!--<select class="common_header_select">-->
          <!--<option value="">选择项目</option>-->
          <!--<option value="1">111</option>-->
          <!--<option value="2">222</option>-->
          <!--<option value="3">333</option>-->
          <!--</select>-->
          <!--<button class="common_header_btn">同步数据</button>-->
          <!--</div>-->
        </div>
        <ul class="common_project_ul">
          <li class="common_projectLIST" @click="linkTOdetail(item.id)" v-for="(item, index) in projet_list">
            <p class="common_projectLIST_projetName">{{textEach(item.pro_name,20)}}</p>
            <p class="common_projectLIST_projetTime">起止时间：{{item.pro_start}}-{{item.pro_end}}</p>
            <div class="common_projectLIST_content">
              <div class="common_projectLIST_LOGO"></div>
              <div class="common_projectLIST_textBOX">
                <p class="common_projectLIST_text">技术领域：{{textEach(item.tec_id.name,12)}}</p>
                <p class="common_projectLIST_text">技术来源：{{item.tec_source}}</p>
                <p class="common_projectLIST_text">知识产权编号：{{item.know_sn}}</p>
                <p class="common_projectLIST_text">研发费用总预算(元)：{{item.pro_total}}</p>
              </div>
            </div>
          </li>
        </ul>

        <!--分页-->
        <ul class="pagination" >
          <li v-show="current != 1" @click="current-- && goto(current)" ><a href="#">上一页</a></li>
          <li v-for="index in pages" @click="goto(index)" :class="{'active':current == index}" :key="index">
            <a href="#" >{{index}}</a>
          </li>
          <li v-show="allpage != current && allpage != 0 " @click="current++ && goto(current++)"><a href="#" >下一页</a></li>
        </ul>
      </div>
    </section>
  </div>
</template>

<script>
  import Routers from '@/template/routers.vue'
  import Header from '@/template/common_header.vue'
  import lu from '@/assets/public.js'
  export default {
    name: 'cost_other_detail',
    components: {
      Routers,
      Header
    },
    data () {
      return {
        projet_list:[],
        /****分页****/
        current:1,
        showItem:5,
        allpage:1
        /***********/
      }
    },
    computed:{
      pages:function(){
        let pag = [];
        if( this.current < this.showItem ){ //如果当前的激活的项 小于要显示的条数
          //总页数和要显示的条数那个大就显示多少条
          let i = Math.min(this.showItem,this.allpage);
          while(i){
            pag.unshift(i--);
          }
        }else{ //当前页数大于显示页数了
          let middle = this.current - Math.floor(this.showItem / 2 ),//从哪里开始
            i = this.showItem;
          if( middle >  (this.allpage - this.showItem)  ){
            middle = (this.allpage - this.showItem) + 1
          }
          while(i--){
            pag.push( middle++ );
          }
        }
        return pag
      }
    },
    mounted: function() {
      this.axios.get('/index/pro_list?page=1').then((res)=>{
        if(res.data.code==1){
          this.projet_list = res.data.data
          this.allpage = res.data.last_page
        }
      })
    },
    methods: {
      /*分页*/
      goto (index) {
        this.current = index;
        //这里可以发送ajax请求
        this.axios.get('/index/pro_list?page='+this.current).then((res)=>{
          if(res.data.code==1){
            this.projet_list = res.data.data
            this.allpage = res.data.last_page
          }
        })
      },
      textEach (str,n) {
        return lu.textEach(str,n)
      },
      linkTOdetail(id){
        this.$router.push('/cost_other_detail/'+id)
      },
    }
  }
</script>

<style scoped>
  @import '../../assets/public.css';
</style>
